package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Role;
import com.itheima.service.RoleService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/role")
public class RoleController {
    @Reference
    private RoleService roleService;

    /**
     * 查询所有角色
     *
     * @return
     */
    @RequestMapping("findall")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Result findall() {
        List<Role> findall = roleService.findall();
        return new Result(true, "查询所有角色成功", findall);
    }

    @RequestMapping("findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult pageResult = roleService.pageQuery(queryPageBean);
        return new Result(true, "分页查询成功", pageResult);
    }

    @RequestMapping("edit")
    public Result edit(@RequestBody Map map) {
        return null;
    }

}
